home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-24 | 1.9 KB | 59 lines |
- import java.lang.*;
- import java.util.*;
- import java.io.*;
- public class AdvUtils extends java.lang.Object implements Serializable
- {
- AdvUtils() {
- }
- // UTILITY METHODS FOR ADVENTURE GAME WRITERS
-
- // Vector Handling
-
- int ObNameAtIndex( String obName, Vector v ) {
- // Try to find a Thing object with the name obName in the Vector v
- //
- // Enumerate the objects in the Vector, v. If no match is
- // made, return the default value -1. If a match is made
- // return the index in v of the found object.
- boolean found = false; // found = true if a match is made
- Thing ob;
- int obIndex = -1; // -1, the default, indicates no match is made
- for (Enumeration e = v.elements(); e.hasMoreElements()&& !found; ) {
- ob = (Thing)e.nextElement();
- if (ob.getname().equalsIgnoreCase(obName)){ // case insensitive test
- found = true;
- obIndex = v.indexOf(ob);
- }
- }
- return obIndex;
- }
-
- /*
- // Here's an alternative implementation of the above method.
- // The main differences are:
- // a: it uses a while loop instead of a for loop
- // b: it increments a counter, i, instead of using the indexOf() method
-
- int ObNameAtIndex( String ObName, Vector V ) {
- Enumeration e = V.elements();
- boolean found = false;
- int i = -1;
- while (e.hasMoreElements() && !found) {
- if (((Thing)e.nextElement()).getname().equalsIgnoreCase(ObName))
- found = true;
- i++;
-
- }
- if (found)
- return i;
- else return -1;
- }
- */
-
- void TransferOb(Object Ob, Vector V1, Vector V2 ) {
- // Move an object Ob from Vector V1 to Vector V2
- V2.addElement(Ob);
- V1.removeElement(Ob);
- }
-
- }